package com.pmt.feedplayer

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.pmt.feedplayer.AppNavigation.AppNavigation
import com.pmt.feedplayer.ui.VideoListViewModel

class MainActivity : ComponentActivity() {
    // 存储权限常量
    private val REQUEST_PERMISSION = 1001
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // 检查并请求存储权限
        if (ContextCompat.checkSelfPermission(
                this,
                Manifest.permission.READ_EXTERNAL_STORAGE
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            ActivityCompat.requestPermissions(
                this,
                arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
                REQUEST_PERMISSION
            )
        }
        
        setContent {
            MaterialTheme {
                Surface(modifier = Modifier) {
                    // 在Composable函数内部创建ViewModel
                    val viewModel = androidx.lifecycle.viewmodel.compose.viewModel<VideoListViewModel>()
                    AppNavigation(viewModel = viewModel)
                }
            }
        }
    }
}